<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>综合练习</title>
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <!-- import Vue before Element -->
    <script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
    <!-- import JavaScript -->
    <script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
</head>
<body>
<div id="app">
    <input type="text" placeholder="员工姓名" v-model="emp.name">
    <input type="text" placeholder="员工工资" v-model="emp.salary">
    <input type="text" placeholder="员工职位" v-model="emp.job">
    <input type="button" value="添加" @click="add">
    <el-table :data="arr">
        <el-table-column prop="name" label="姓名" width="200"></el-table-column>
        <el-table-column prop="salary" label="工资" width="200"></el-table-column>
        <el-table-column prop="job" label="职位" width="200"></el-table-column>
        <!--如果表格中的内容不是对象数组中的属性而是自定义的效果,
        需要按照文档中提供的这种固定写法-->
        <el-table-column label="操作" width="200">
            <!--自定义列必须添加template标签以及slot-scope
            scope是定义一个变量名称,此变量里面装着当前行的相关信息
            scope.$index 当前行对应的下标
            scope.row  当前行对应数组的对象
            -->
            <template slot-scope="scope">
               <el-button
                        size="mini"
                        type="danger"
                        @click="handleDelete(scope.$index, scope.row)">删除</el-button>
            </template>
        </el-table-column>
    </el-table>
</div>
</body>
<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                emp:{name:"",salary:"",job:""},
                arr:[
                    {name:"张三",salary:5000,job:"销售"},
                    {name:"李四",salary: 4000,job:"人事"},
                    {name:"王五",salary: 7000,job:"程序员"}
                ]
            }
        },
        methods:{
            add(){
                this.arr.push({
                    name:this.emp.name,
                    salary:this.emp.salary,
                    job:this.emp.job
                })
            },
            // i代表删除的下表,emp删除的对象
            handleDelete(i,emp) {
                v.arr.splice(i,1)
                v.$message("删除了"+emp.name)
            }
        }
    })
</script>
</html>